package at.codebase.core;


/**
 * 
 * @author Lukas Pfeifhofer <lukas.pfeifhofer@devlabs.pro>
 *
 */
public class RichtTextFormatter {
	
	public static String sampleText =
					"asdf *0* *asdf* asdf *as*d\n"+
					"*asd* _fasdasd_ f\n"+
					" *as asd addf* asdf\n"+
					"asd _fasdasd_ f\n"+
					" * asdfasdf\n"+
					" * asdfasdf\n"+
					" * asdfasdf\n"+
					"asdfasdf\n"+
					"asdfasdf\n"+
					"asdfasdf\n";
			
	
	public static String toRichText(String rawText){
		//Mhh too less time for that...
		return rawText;
		/*
		StringBuffer sB = new StringBuffer(rawText);
		Matcher matcher;
		
		Pattern listElements = Pattern.compile("^"+"\\s*\\*\\s*"+"([^\\*\n.]+)\n", Pattern.MULTILINE);
		Pattern boldTextPattern = Pattern.compile("\\*([^\\*]+)\\*");
		Pattern italicTextPattern = Pattern.compile("\\_([^\\_]+)\\_");
		
		//LIST ELEMENTS
		matcher = listElements.matcher(sB.toString());
		sB = new StringBuffer();
		while (matcher.find()) {
			String text = matcher.group(1);
			matcher.appendReplacement(sB, Matcher.quoteReplacement("<lu><li>"+text+"</li></lu>\n"));
		}
		matcher.appendTail(sB);
		
		//BOLD
		matcher = boldTextPattern.matcher(sB.toString());
		sB = new StringBuffer();
		while (matcher.find()) {
			String text = matcher.group(1);
			matcher.appendReplacement(sB, Matcher.quoteReplacement("<b>"+text+"</b>"));
		}
		matcher.appendTail(sB);
		
		//ITALIC
		
		matcher = italicTextPattern.matcher(sB.toString());
		sB = new StringBuffer();
		while (matcher.find()) {
			String text = matcher.group(1);
			matcher.appendReplacement(sB, Matcher.quoteReplacement("<i>"+text+"</i>"));
		}
		matcher.appendTail(sB);
		
		
		return sB.toString();
		*/
	}
	
	public static void main(String[] args){
		String input = sampleText;
		System.out.println(input);
		System.out.println();
		
		String richText = toRichText(input);
		
		System.out.println();
		System.out.println(richText);

	}
	
}
